<?php

/**
 * 
 */
class App_Plugins_Default_Layout extends Zend_Controller_Plugin_Abstract
{
	/**
	 * 
	 * @var Zend_Controller_Request_Abstract
	 */
	protected $_request;

        /**
	 * 
	 * (non-PHPdoc)
	 * @see Zend_Controller_Plugin_Abstract::dispatchLoopStartup()
	 */
	public function dispatchLoopStartup ( Zend_Controller_Request_Abstract $request )
	{
		$this->_request = $request;
		
		$this->_configLayout();
		$this->_configView();
		
		$this->_includeJsController();
		$this->_includeCssController();
	}
	
	/**
	 * 
	 */
	protected function _configView ()
	{
		$view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view');
		
		$view->docType('XHTML1_TRANSITIONAL');
		
		//Title
		$view->headTitle( Zend_Registry::get('config')->geral->title );
		
		$view->headMeta()->appendName('charset', 'utf-8');
		
		//Styles
		$view->headLink()->appendStylesheet($view->baseUrl('public/styles/default/layout.css'), '');
		$view->headLink()->appendStylesheet($view->baseUrl('public/styles/default/paginas.css'), '');
		$view->headLink()->appendStylesheet($view->baseUrl('public/styles/default/jquery.jqzoom.css'), '');
		$view->headLink()->appendStylesheet($view->baseUrl('public/styles/default/prettyPhoto.css'), 'screen');
		
		//Scripts
		//$view->headScript()->appendFile('https://getfirebug.com/firebug-lite-debug.js');
                
                $view->headScript()->appendFile($view->baseUrl('public/scripts/jquery.js'));
                $view->headScript()->appendFile($view->baseUrl('public/scripts/jquery.jqzoom-core.js'));
                $view->headScript()->appendFile($view->baseUrl('public/scripts/jquery.prettyPhoto.js'));
		
	}
	
	/**
	 * 
	 */
	protected function _configLayout ()
	{
		Zend_Layout::getMvcInstance()->setLayoutPath(APPLICATION_PATH . '/modules/default/layouts/');
	}

	/**
	 * 
	 */
	protected function _includeJsController ()
	{
		$ds = DIRECTORY_SEPARATOR;
		
		$file = 'public' . $ds . 'scripts' . $ds . $this->_request->getModuleName() . $ds . 'controller' . $ds . $this->_request->getControllerName() . '.js';
		
		if ( file_exists(APPLICATION_PATH . $ds . '..' . $ds . $file) ) {
			$view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view');
			$view->headScript()->appendFile($view->baseUrl($file));
		}
	}

	/**
	 * 
	 */
	protected function _includeCssController ()
	{
		$ds = DIRECTORY_SEPARATOR;
		
		$file = 'public' . $ds . 'styles' . $ds . $this->_request->getModuleName() . $ds . 'controller' . $ds . $this->_request->getControllerName() . '.css';
		
		if ( file_exists(APPLICATION_PATH . $ds . '..' . $ds . $file) ) {
			$view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view');
			$view->headLink()->appendStylesheet($view->baseUrl($file));
		}
	}
        
        public static function cache(){
            // frontais opções finais
            $frontendOptions = array(
                'lifetime' => 86400
            );

            // opções de back-end
            $backendOptions = array(
                'cache_dir' => APPLICATION_PATH . '/cache'// Diretório onde colocar os arquivos de cache
            );

            // tornar objeto
            return Zend_Cache::factory('Output', 'File', $frontendOptions, $backendOptions);
    }
}